﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAO;
using System.Data;

namespace BUS
{
    public static class MonAnBUS
    {
        public static bool themMonAn(MONAN monan)
        {
            return MonAnDAO.themMonAn(monan);
        }

        public static bool capNhatMonAn(MONAN monan)
        {
            return MonAnDAO.capNhatMonAn(monan);
        }

        public static int layMaMonAnLonNhat()
        {
            return MonAnDAO.layMaMonAnLonNhat();
        }

        public static List<MONAN> layDSMA()
        {
            return MonAnDAO.layDSMA();
        }

        public static DataTable layNVLMonAnDauTien()
        {
            DataTable dt = new DataTable();
            MONAN monan = MonAnDAO.layMonAnDauTien();

            DataColumn maNVL = new DataColumn("Mã nguyên vật liệu");
            dt.Columns.Add(maNVL);
            dt.Columns[0].ReadOnly = true;

            DataColumn tenNVL = new DataColumn("Tên nguyên vật liệu");
            dt.Columns.Add(tenNVL);
            dt.Columns[1].ReadOnly = true;

            DataColumn soLuongNVL = new DataColumn("Số lượng cần thiết");
            dt.Columns.Add(soLuongNVL);
            dt.Columns[2].ReadOnly = true;

            foreach (DS_NVL_MONAN nvl_ma in monan.DS_NVL_MONAN)
            {
                DataRow row = dt.NewRow();
                row[0] = nvl_ma.MaNVL;
                row[1] = NguyenVatLieuBUS.layNVL(nvl_ma.MaNVL).TenNVL;
                row[2] = nvl_ma.SoLuongNVLCan;
                dt.Rows.Add(row);
            }

            return dt;
        }

        public static DataTable layNVLMonAn(int maMA)
        {
            DataTable dt = new DataTable();
            MONAN monan = MonAnDAO.layMonAn(maMA);

            DataColumn maNVL = new DataColumn("MaNVL");
            dt.Columns.Add(maNVL);

            DataColumn tenNVL = new DataColumn("TenNVL");
            dt.Columns.Add(tenNVL);

            DataColumn soLuongNVL = new DataColumn("SoLuongNVL");
            dt.Columns.Add(soLuongNVL);

            foreach (DS_NVL_MONAN nvl_ma in monan.DS_NVL_MONAN)
            {
                DataRow row = dt.NewRow();
                row[0] = nvl_ma.MaNVL;
                row[1] = nvl_ma.NGUYENVATLIEU.TenNVL;
                row[2] = nvl_ma.SoLuongNVLCan;
                dt.Rows.Add(row);
            }
            return dt;
        }

        public static MONAN layMonAn(int maMA)
        {
            return MonAnDAO.layMonAn(maMA);
        }
    }
}
